﻿using System;
using System.Collections.Generic;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using LoA.Shared.Screen;
using LoA.Shared.Screen.Entities;
using System.Collections.ObjectModel;

namespace LoA.ScreenManager {
	public static class ScreenMenuExporter {
		public static void Export( ) {
			// Graphic options screen

			var graphicOptionsScreenEntities = new List<IScreenEntry>( );

			graphicOptionsScreenEntities.Add(new SettingEntry("Resolution", "GraphicResolution", EntryControl.Selector, SettingValuesGenerator.Resolutions( )));

			graphicOptionsScreenEntities.Add(new SettingEntry("Gamma", "GraphicGamma", EntryControl.Slider, SettingValuesGenerator.Percentage(0, 100, 5), 10));

			graphicOptionsScreenEntities.Add(new SettingEntry("Fullscrean", "GraphicFullscrean", EntryControl.ToggleSwitch, SettingValuesGenerator.YesNo( )));

			graphicOptionsScreenEntities.Add(new SettingEntry("Multi sampling", "GraphicMultisampling", EntryControl.Selector, SettingValuesGenerator.Numeric(0, 16, 1)));

			graphicOptionsScreenEntities.Add(new ActionEntry("Back", EntryAction.BackMenu));

			var graphicOptionsScreen = new ScreenEntity("Graphic setup", graphicOptionsScreenEntities.AsReadOnly( ));

			// Sound options screen
			var soundOptionsScreenEntities = new List<IScreenEntry>( );

			soundOptionsScreenEntities.Add(new LinkEntry("Music volume", null));

			soundOptionsScreenEntities.Add(new LinkEntry("Sounds volume", null));

			soundOptionsScreenEntities.Add(new LinkEntry("Voices volume", null));

			soundOptionsScreenEntities.Add(new LinkEntry("Nature sounds volume", null));

			soundOptionsScreenEntities.Add(new LinkEntry("Background sounds volume", null));

			soundOptionsScreenEntities.Add(new ActionEntry("Back", EntryAction.BackMenu));

			var soundOptionsScreen = new ScreenEntity("Sounds setup", soundOptionsScreenEntities.AsReadOnly( ));

			// Network options screen
			var networkOptionsScreenEntities = new List<IScreenEntry>( );

			networkOptionsScreenEntities.Add(new LinkEntry("Graphic", null));

			networkOptionsScreenEntities.Add(new LinkEntry("Sound", null));

			networkOptionsScreenEntities.Add(new LinkEntry("Network", null));

			networkOptionsScreenEntities.Add(new ActionEntry("Back", EntryAction.BackMenu));

			var networkOptionsScreen = new ScreenEntity("Network setup", networkOptionsScreenEntities.AsReadOnly( ));

			// Controls options screen
			var controlsOptionsScreenEntities = new List<IScreenEntry>( );

			networkOptionsScreenEntities.Add(new LinkEntry("Graphic", null));

			networkOptionsScreenEntities.Add(new LinkEntry("Sound", null));

			networkOptionsScreenEntities.Add(new LinkEntry("Network", null));

			networkOptionsScreenEntities.Add(new ActionEntry("Back", EntryAction.BackMenu));

			var controlsOptionsScreen = new ScreenEntity("Controls setup", controlsOptionsScreenEntities.AsReadOnly( ));

			// Options screen
			var optionsScreenEntities = new List<IScreenEntry>( );

			optionsScreenEntities.Add(new LinkEntry("Graphic", graphicOptionsScreen));

			optionsScreenEntities.Add(new LinkEntry("Sound", soundOptionsScreen));

			optionsScreenEntities.Add(new LinkEntry("Network", networkOptionsScreen));

			optionsScreenEntities.Add(new LinkEntry("Controls", networkOptionsScreen));

			optionsScreenEntities.Add(new ActionEntry("Back", EntryAction.BackMenu));

			var optionsScreen = new ScreenEntity("Options", optionsScreenEntities.AsReadOnly( ));

			// Menu screen
			var menuScreenEntities = new List<IScreenEntry>( );

			menuScreenEntities.Add(new ActionEntry("Play game", EntryAction.PlayGame));

			menuScreenEntities.Add(new LinkEntry("Options", optionsScreen));

			menuScreenEntities.Add(new PopupEntry("Exit", "Are you sure you want to exit?", EntryAction.ExitGame, EntryButtons.OKCancel));

			var menuScreen = new ScreenEntity(menuScreenEntities.AsReadOnly( ));

			XmlWriterSettings settings = new XmlWriterSettings( );
			settings.Indent = true;

			using (XmlWriter writer = XmlWriter.Create("menu_new.xml", settings)) {
				IntermediateSerializer.Serialize(writer, menuScreen, null);
			}

			var suspendMenu = new PopupEntry("Are you sure?", EntryAction.OpenMenu, EntryButtons.OKCancel);

			using (XmlWriter writer = XmlWriter.Create("suspendMenu_new.xml", settings)) {
				IntermediateSerializer.Serialize(writer, suspendMenu, null);
			}
		}
	}
}
